/**
*      author: Y_Yao
*      created: 2024-11-26 16:00:40
**/

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 1000 + 7;
int dp[N][N];

void solve()
{
    int r;
    cin >> r;
    vector<vector<int>> a(N);
    for(int i = 1;i <= r;i++)
    {
        for(int j = 1;j <= i;j++)
        {
            if(j == 1) a[i].push_back(0);
            int t;
            cin >> t;
            a[i].push_back(t);
        }
        a[i].push_back(0);
    }

    dp[1][1] = a[1][1];
    for(int i = 2;i <= r;i++)
    {
        for(int j = 1;j <= i;j++)
        {
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-1]) + a[i][j];
        }
    }

    int ret = 0;
    for(int i = 1;i < a[r].size();i++)
    {
        ret = max(ret,dp[r][i]);
    }

    cout << ret << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}